﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SilkeyERP.Model
{
    public partial class SalesPriceListDetails
    {
        public decimal CurrentBuyPriceWTax { get { return GetCurrentBuyPriceWTax(); } }
        public decimal CurrentBuyPriceWOutTax { get { return GetCurrentBuyPriceWOutTax(); } }

        private decimal GetCurrentBuyPriceWTax()
        {
            try
            {
                var buyPriceList = new BuyPriceListRepository().GetAll();
                Model.BuyPriceListDetails currentBuyProduct = null;
                foreach (var item in buyPriceList)
                {
                    currentBuyProduct = item.BuyPriceListDetails.Where(x => x.ProductID == this.ProductID).SingleOrDefault();
                    break;
                }
                if (currentBuyProduct != null)
                    return currentBuyProduct.CurrentPriceWTax;
                else
                    return 0;
            }
            catch
            {                
                return decimal.MinValue;
            }

        }

        private decimal GetCurrentBuyPriceWOutTax()
        {
            try
            {
                var buyPriceList = new BuyPriceListRepository().GetAll();
                Model.BuyPriceListDetails currentBuyProduct = null;
                foreach (var item in buyPriceList)
                {
                    currentBuyProduct = item.BuyPriceListDetails.Where(x => x.ProductID == this.ProductID).SingleOrDefault();
                    break;
                }
                if (currentBuyProduct != null)
                    return currentBuyProduct.CurrentPriceWOutTax;
                else
                    return 0;
            }
            catch
            {

                return decimal.MinValue;
            }

        }
    }
}
